package com.example.clublesson01.fragments
import com.bw.kf.lib_base.base.BaseFragment
import com.example.clublesson01.adapter.GroupIndexAdapter
import com.example.clublesson01.adapter.ImageAdapter2
import com.example.clublesson01.adapter.LookCarAdapter
import com.example.clublesson01.adapter.LookCarAdapter2
import com.example.clublesson01.adapter.LookCarAdapter3
import com.example.clublesson01.databinding.FragmentLookCartBinding
import com.example.clublesson01.fragments.lookcar.LookCarViewModel


class LookCartFragment : BaseFragment<FragmentLookCartBinding, LookCarViewModel>() {
     lateinit var adapter: LookCarAdapter
     lateinit var adapter2: LookCarAdapter2
     lateinit var adapterIndex: GroupIndexAdapter
    val imgs=mutableListOf<String>()
     lateinit var adapter3: LookCarAdapter3
     lateinit var imageAdapter: ImageAdapter2
    override fun iniView() {
        viewModel.getBannerList()
        viewModel.getGroupList()
        viewModel.getGroupIndex()
        adapter= LookCarAdapter()
        adapterIndex= GroupIndexAdapter()
        adapter2= LookCarAdapter2()
        adapter3= LookCarAdapter3()
        binding.rec.adapter=adapter
        binding.rec1.adapter=adapter2
        binding.rec2.adapter=adapter3
        binding.recTabs.adapter=adapterIndex
    }
    override fun iniData() {
       viewModel.success.observe(this){
            adapter.data.clear()
           adapter.data.addAll(it.data[0].mallGoodsInfoPageResponseList)
           adapter2.data.addAll(it.data[1].mallGoodsInfoPageResponseList)
           adapter3.data.addAll(it.data[2].mallGoodsInfoPageResponseList)
           adapter.notifyDataSetChanged()
       }
        viewModel.successBanner.observe(this){ it ->
            if (it.code==200){
                 it.data.forEach{
                     imgs.add(it.imageUrl)
                 }
                 imageAdapter= ImageAdapter2(imgs)
                 binding.banner2.setAdapter(imageAdapter)
                 binding.banner2.start()
             }

        }
        viewModel.successGroup.observe(this){
            adapterIndex.data.clear()
            adapterIndex.data.addAll(it.data)
            adapterIndex.notifyDataSetChanged()
        }

    }
    override fun getViewModel(): Class<LookCarViewModel> {
        return LookCarViewModel::class.java
    }

    override fun Layoutid(): Int {
        return com.example.clublesson01.R.layout.fragment_look_cart
    }

}